﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PBCodeGen
{
    public partial class Form1 : Form
    {
     

        public Form1()
        {
            InitializeComponent();

            LocalConfig.LoadLocalConfig();

            this.textBox1.Text = LocalConfig.ProtoFilePath;
            this.textBox2.Text = LocalConfig.CSharpHandlerPath;
            this.textBox3.Text = LocalConfig.CSharpDefinePath;
            this.textBox4.Text = LocalConfig.GoHandlerPath;
            this.textBox5.Text = LocalConfig.GoDefinePath;
        }

        //proto文件路径选择
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog filedialog = new OpenFileDialog();
            filedialog.Title = "选择protobuf消息文件";
            filedialog.Filter = "proto文件(*.proto)|*.proto";
            if (filedialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = filedialog.FileName;
                this.textBox1.Text = fileName;
            }
            else 
            {
                MessageBox.Show("选择失败");
            }
        }

        //C# Handler路径选择
        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderDialog = new FolderBrowserDialog();
            folderDialog.Description = "请选择C# Handler路径";
            if (folderDialog.ShowDialog() == DialogResult.OK)  
            {
                this.textBox2.Text = folderDialog.SelectedPath;
            }
        }

        //C# 消息定义路径选择
        private void button3_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderDialog = new FolderBrowserDialog();
            folderDialog.Description = "请选择C# 定义路径";
            if (folderDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox3.Text = folderDialog.SelectedPath;
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {

            LocalConfig.SaveLocalConfig(this.textBox1.Text,this.textBox2.Text,this.textBox3.Text,this.textBox4.Text,this.textBox5.Text);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            CodeGenManager.GenAll(this.textBox1.Text,this.textBox3.Text,this.textBox2.Text,this.textBox4.Text,this.textBox5.Text);

            MessageBox.Show("生成成功");
        }

        //Go Handler路径
        private void button5_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderDialog = new FolderBrowserDialog();
            folderDialog.Description = "请选择Go Handler路径";
            if (folderDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox4.Text = folderDialog.SelectedPath;
            }
        }
        //Go 消息定义路径
        private void button6_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderDialog = new FolderBrowserDialog();
            folderDialog.Description = "请选择Go 消息定义路径";
            if (folderDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBox5.Text = folderDialog.SelectedPath;
            }
        }


    }
}
